import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/views/home'
import { frontRouter } from '@/router/frontRouter'
import { backRouter } from '@/router/backRouter'

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}
Vue.use(Router)

const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login'),
    meta: {
      title: '登录'
    }
  },
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      title: '首页爸爸'
    },
    children: [...backRouter, ...frontRouter]
  }
]

const router = new Router({
  routes
})
router.afterEach((to, from) => {
  document.title = to.meta.title;
})
export default router
